using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Cysharp.Threading.Tasks;
using Unity.VisualScripting;
using QFramework;
using DG.Tweening;

public class UIStartPanel : MonoBehaviour,IController
{
    public Button m_Button;
    public CanvasGroup canvasGroup;
    public Material material;

    public IArchitecture GetArchitecture() => MainArchitecture.Interface;

    private void Awake() 
    {
        m_Button.onClick.AddListener(OnButtonClick);
        material.SetFloat("_Pow", 1);
        material.SetFloat("_Alpha", 0.15f);
    }

    private async void OnButtonClick()
    {
        Debug.Log("Start game");
        var audioSystem = this.GetSystem<AudioSystem>();
        audioSystem.PlaySoundEffect("Sound/effects/warp2");
        DOTween.To(() => material.GetFloat("_Pow"), x => material.SetFloat("_Pow", x), 70, 6).SetEase(Ease.InCubic);
        await DOTween.To(()=> canvasGroup.alpha,x => canvasGroup.alpha = x,0,3);
        await UniTask.Delay(2000);
        await DOTween.To(() => material.GetFloat("_Alpha"), x => material.SetFloat("_Alpha", x), 0, 1).SetEase(Ease.InCubic);

        
        this.GetSystem<UIManager>().OpenUIPanel("UIPanel/UIChooseStage/UIChooseStage").Forget();
    }
    private void OnDestroy() 
    {
        material.SetFloat("_Pow", 1);
        material.SetFloat("_Alpha", 0.15f);
    }
}
